package com.king.business.service.impl;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.king.business.domain.Deal;
import com.king.business.mapper.DealMapper;
import com.king.business.service.IDealService;
import com.king.common.core.domain.entity.SysUser;
import com.king.common.core.domain.model.LoginUser;
import com.king.common.utils.SecurityUtils;
import com.king.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class DealServiceImpl extends ServiceImpl<DealMapper, Deal> implements IDealService {
    @Autowired
    private IDealService dealService;
    @Autowired
    private ISysUserService userService;

    @Override
    public List<Deal> selectDealList(Deal deal) {
        return getBaseMapper().selectDealList(deal);
    }

    @Override
    public boolean save(Deal entity) {
        String idStr = IdWorker.getIdStr();
        entity.setId(idStr);
        SysUser sysUser = userService.selectUserById(entity.getUserId());
        entity.setUsername(sysUser.getNickName());
        LoginUser loginUser = SecurityUtils.getLoginUser();
        entity.setOperate(String.valueOf(loginUser.getUserId()));
        entity.setOperationTime(new Date());
        return super.save(entity);
    }
}
